<?php
/*
* Author: Nguyen Hai Nam
* Plugin: menuleft
* Desc	: Menu right of Petaco Website
* Date	: 12/12/2011
*/
class MenuLeftPlugin extends Pick_Core_Plugin{
	
	function MenuLeftPlugin(){
		parent::Pick_Core_Plugin();
		$this->namePlugin = "menuleft";
		$this->descriptionPlugin = "This is menu left of product pages";
	}
	public function getContent(){
		//echo $this->op;
		switch($this->op){
			case 'grouphistory':{
				$slug = $this->request->get("slug", 'group-history');
				$this->template->assign('slug', $slug); 
			}break;
			case 'aboutus':{
				$slug = $this->request->get("slug");
				$this->template->assign('slug', $slug);	
			}break;
            case 'contactus':{
                $slug = $this->request->get("slug");
                $this->template->assign('slug', $slug); 
            }break;
			case 'randd':{
				$newscategory = new Pick_Dao_NewsCategory();
				$news = new Pick_Dao_News();
				$id = $this->request->get("id");
				// If ID empty, it's will get default...
				$objCategory = $newscategory->getObjectFromSlug('r-d');
				$objMenus = $news->getObjectsFromCId(1, $objCategory->getField('id'));
				if(isset($objMenus['data']))
					$objMenus = $objMenus['data'];
				$this->template->assign('id', $id);
				$this->template->assign('objCategory', $objCategory);
				$this->template->assign('objMenus', $objMenus);
				
			}break;
			case 'environment':{
				$newscategory = new Pick_Dao_NewsCategory();
				$news = new Pick_Dao_News();
				$id = $this->request->get("id");
				// If ID empty, it's will get default...
				if(empty($id)){
					$objproductcategorydefault = $newscategory->getObjects(1, "status=1 AND cid = 0", array('position'=>"ASC"), 1);
					if(isset($objproductcategorydefault['data'][0]) && is_object($objproductcategorydefault['data'][0])){
						$id = $objproductcategorydefault['data'][0]->getField('id');
					}	
				}
				$objCategory = $newscategory->getObjectFromSlug('environment');
				$objMenus = $news->getObjectsFromCId(1, $objCategory->getField('id'));
				if(isset($objMenus['data']))
					$objMenus = $objMenus['data'];
				$this->template->assign('id', $id);
				$this->template->assign('objCategory', $objCategory);
				$this->template->assign('objMenus', $objMenus);
				
			}break;
			case 'region':{
                $region = new Pick_Dao_Regions();
                $id = $this->request->get("id");
                // If ID empty, it's will get default...
                
                $objRegion = $region->getObject($id);
                $objMenus = $region->getObjects(1, '1=1', array('position'=>'ASC'), '');
                if(isset($objMenus['data']))
                    $objMenus = $objMenus['data'];
                $this->template->assign('id', $id);
                $this->template->assign('objRegion', $objRegion);
                $this->template->assign('objMenus', $objMenus);
			}break;
			case 'careers':{
				
                $newscategory = new Pick_Dao_NewsCategory();
                $news = new Pick_Dao_News();
                $id = $this->request->get("id");
                // If ID empty, it's will get default...
                
                $objCategory = $newscategory->getObjectFromSlug('careers');
                $objMenus = $news->getObjectsFromCId(1, $objCategory->getField('id'));
                if(isset($objMenus['data']))
                    $objMenus = $objMenus['data'];
                $this->template->assign('id', $id);
                $this->template->assign('objCategory', $objCategory);
                $this->template->assign('objMenus', $objMenus);
				
			}break;
			case 'newsmediadetail':{}
			case 'newsmedia':{
				
                $newscategory = new Pick_Dao_NewsCategory();
				$news = new Pick_Dao_News();
                $id = $this->request->get("id");
                // If ID empty, it's will get default...
				if($this->op == 'newsmedia'){
					if(empty($id)){
						$objproductcategorydefault = $newscategory->getObjects(1, "status=1 AND cid = 0", array('position'=>"ASC"), 1);
						if(isset($objproductcategorydefault['data'][0]) && is_object($objproductcategorydefault['data'][0])){
							$id = $objproductcategorydefault['data'][0]->getField('id');
						}   
					}
				}elseif($this->op == 'newsmediadetail'){
					if(!empty($id)){
						$id = $news->getObject($id)->getField('cid');
					}
				}
                $objCategory = $newscategory->getObjectFromSlug('news-media');
                $objMenus = $newscategory->getObjectsFromCId(1, $objCategory->getField('id'), array('position'=>'DESC'));
                if(isset($objMenus['data']))
                    $objMenus = $objMenus['data'];
                $this->template->assign('id', $id);
				$this->template->assign('newscategory', $newscategory);
                $this->template->assign('objCategory', $objCategory);
                $this->template->assign('objMenus', $objMenus);
				
			}break;
			case 'referenceprojects':{
				$countries = new Pick_Dao_Countries();
				$id = $this->request->get("id");
				$objCountry = $countries->getObject($id);
				$objMenus = $countries->getObjects(1, 'status = 1', array('position'=>'ASC'));
				if(isset($objMenus['data']))
					$objMenus = $objMenus['data'];
				$this->template->assign('id', $id);
				$this->template->assign('objCountry', $objCountry);
				$this->template->assign('objMenus', $objMenus);
			};break;
			default:{
				$productcategory = new Pick_Dao_ProductCategory();
				$id = $this->request->get("id");
				// If ID empty, it's will get default...
				if(empty($id)){
					$objproductcategorydefault = $productcategory->getObjects(1, "status=1 AND cid = 0", array('position'=>"ASC"), 1);
					if(isset($objproductcategorydefault['data'][0]) && is_object($objproductcategorydefault['data'][0])){
						$id = $objproductcategorydefault['data'][0]->getField('id');
					}	
				}
				$objCategory = $productcategory->getObject($id);
				$objMenus = $productcategory->getObjects(1, ' cid=0 ', array('position'=>'ASC'));
				$this->template->assign('productcategory', $productcategory);
				$this->template->assign('id', $id);
				$this->template->assign('objCategory', $objCategory);
				$this->template->assign('objMenus', $objMenus['data']);
			}break;
		}
	}
}